class Ajax {
  // constructor(method, url, data) {
  constructor({method = "GET", url: u, data = null}) {
    this.method = method
    this.url = u
    this.data = data
  }
  http() {
    // console.log(this)
    return new Promise((resolve, reject) => {
      let xhr = new XMLHttpRequest()
      xhr.open(this.method, this.url)
      xhr.send(this.data)
      xhr.responseType = "json"
      xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
          if (xhr.status === 200) {
            resolve(xhr.response)
          } else {
            reject(xhr.response)
          }
        }
      }
    })
  }
}

new Ajax({
  url: "https://veihwwnelcwq.leanapp.cn/bmi"
}).http().then(res => {
  console.log(res)
}).catch(e => {
  console.log(e)
})



